#include "common.h"
#include "level.h"

#include "infoform.h"

LRESULT CALLBACK InfoFormProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	return false;
}

InfoForm::InfoForm( int id, HWND hParent )
:	_hParent( hParent )
,	_hWnd( NULL )
,	_id( id )
{
	Core& core = Core::GetInstance();
	_hWnd = CreateDialog(
		core.GetInstanceHandle(),
		MAKEINTRESOURCE( IDD_INFOFORM ),
		_hParent,
		( DLGPROC )InfoFormProc );

	RECT rc;
	GetClientRect( _hWnd, &rc );
	SetWindowPos( _hWnd, HWND_TOP, 2, 22, rc.right, rc.bottom, 0 ); 
}

InfoForm::~InfoForm()
{
};

void InfoForm::SetInfos( Level* lvInfos )
{
	int restrict = lvInfos->GetRestrictTime();
	float elasped = lvInfos->GetElaspedTime();

	int min = static_cast< int >( elasped / 60.0f );
	int sec = static_cast< int >( fmod( elasped, 60.0f ) );
	int rmin = static_cast< int >( ( restrict - elasped + 1 ) / 60.0f );
	int rsec = static_cast< int >( restrict - elasped + 1 ) % 60;


	sprintf_s( _timeStr, sizeof( _timeStr ), "%02d:%02d(%02d:%02d)", min, sec, rmin, rsec );
	SetDlgItemTextA( _hWnd, IDC_EDIT_ELASPED, _timeStr );

}
